package ${location}.common;

import ${location}.exception.Asserts;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

import static ${location}.common.Constant.*;

/**
 * 分页参数
 *
 * @author ${author}
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageQuery implements Serializable {

	@ApiModelProperty(value = "当前页")
	private Integer page;
	@ApiModelProperty(value = "分页大小")
	private Integer size;

	public void checkPageSize() {
		if (this.page == null) {
			Asserts.error("page不能为空!");
		}
		if (this.size == null) {
			Asserts.error("size不能为空!");
		}
		if (this.page <= 0) {
			this.page = DEFAULT_PAGE;
		}
		if (this.size <= 0 || this.page > MAX_SIZE) {
			this.size = DEFAULT_SIZE;
		}
	}

	private static final long serialVersionUID = 1L;
}
